ig.module(
	'game.entities.base.word'
)
.requires(
	'impact.entity'    
)

.defines(function()
{
    Word = ig.Class.extend(
    {
        line: 0,
        column: 0,
        vertical: false,
        word: '#',
        solution: null,
        overlayType: 'red',
        
        setWord: function(w)
        {
            this.word = w;
            this.solution = new Array();
            
            for (var i = 0; i < w.length; ++i)
            {
                this.solution[i] = false;
            }
        },
        
        isLetter: function(c, l)
        {
            if (this.vertical == true)
            {
                if (this.column == c)
                {
                    if (l >= this.line && l <= this.line + this.word.length - 1)
                    {
                        return true;
                    }
                }                
            }
            else
            {
                if (this.line == l)
                {
                    if (c >= this.column && c <= this.column + this.word.length - 1)
                    {                        
                        return true;                      
                    }
                }
            }
            
            return false;
        },
        
        checkClickedLetter: function(c, l)
        {
            if (this.isLetter(c, l) == true)
            {
                if (this.vertical == true)
                {
                    var index = l - this.line;
                        
                    if (this.solution[index] == false)
                    {
                        this.solution[index] = true;
                        ig.global.numberOfPicks++;
                    }                      
                }
                else
                {
                    var index = c - this.column;
                    
                    if (this.solution[index] == false)
                    {
                        this.solution[index] = true;
                        ig.global.numberOfPicks++;
                    }                      
                }
            }                
        },
        
        isSolved: function()
        {
            for (var i = 0; i < this.solution.length; ++ i)
            {                
                if (this.solution[i] == false)
                {
                    return false;
                }
            }
            
            return true;
        },
        
        draw: function(overlay, offsetX, offsetY)
        {                    
            for (var i = 0; i < this.solution.length; ++ i)
            {                
                if (this.solution[i] == true)
                {                                     
                    if (this.vertical == true)
                    {
                        var x = this.column * offsetX;
                        var y = (this.line + i) * offsetY;
                        
                        overlay.draw(x, y);                              
                    }
                    else
                    {
                        var x = (this.column + i) * offsetX;
                        var y = this.line * offsetY;
                        
                        overlay.draw(x, y);                    
                    }
                }
            }
        }
    });
});